<?php
    session_start();
    include('top.php');
    include('../sql.php');
    $box_id = $_GET['id'];
    $box_sql = "select * from speciality where id = $box_id";
    $box_result = $link->query($box_sql);
    $box_row = mysqli_fetch_array($box_result);
?>
<div class="home-container-body">
    <?php include('nav.php'); ?>
</div>

<div class="admin_hone-content">
    <form method="post" id="sForm">
        <table width="100%">
            <tr>
                <td>专业名称</td>
                <td>
                    <input type="text" name="speciality" value="<?php echo $box_row['name']; ?>">
                </td>
            </tr>
            <tr>
                <td>学位授予门类</td>
                <td>
                    <input type="text" name="zylb" value="<?php echo $box_row['mlzyl']; ?>">
                </td>
            </tr>
            <tr>
                <td>门类、专业类</td>
                <td>
                    <input type="text" name="xw" value="<?php echo $box_row['xwsyml']; ?>">
                </td>
            </tr>
            <tr>
                <td>学制</td>
                <td>
                    <input type="text" name="years" value="<?php echo $box_row['years']; ?>">
                </td>
            </tr>
            <tr>
                <td>培养院系</td>
                <td>
                    <input type="text" name="school" value="<?php echo $box_row['school']; ?>">
                </td>
            </tr>
            <tr>
                <td>拟招生人数</td>
                <td>
                    <input type="text" name="total" value="<?php echo $box_row['total']; ?>">
                </td>
            </tr>
            <tr>
                <td>学费</td>
                <td>
                    <input type="text" name="price" value="<?php echo $box_row['price']; ?>">
                </td>
            </tr>
            <tr>
                <td>操作</td>
                <td>
                    <input type="submit" value="修改">
                    <div id="sResult"></div>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript" src="../static/js/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('#sForm').on('submit', function(e){
            e.preventDefault();
            var formData = $(this).serialize();

            $.ajax({
                url: 'control.php?action=updatespeciality&id=<?php echo $box_id; ?>',
                type: 'POST',
                data: formData,
                success: function(response){
                    $('#sResult').empty();
                    $('#sResult').html(response);
                    location.reload();
                },
                error: function(error){
                    console.log(error);
                    $('#sResult').html('失败，请稍后再试。');
                }
            });
        });
    });
</script>
<?php include('bottom.php'); ?>